#include <stdio.h>

unsigned setbits(unsigned x, unsigned p, unsigned n, unsigned y);

int main()
{
    printf("out = %d", setbits(0b11111111, 2, 3, 0b1110000));
    return 0;
}

unsigned setbits(unsigned x, unsigned p, unsigned n, unsigned y)
{
    return (~(~(~0 << n) << p) & x ) | ((~(~0 << n) & y) << p);
}